package com.kinyx.framework.db.sentence.str.demo.delete;

import org.junit.Assert;
import org.junit.Test;

import com.kinyx.framework.db.sentence.str.DELETE;
import com.kinyx.framework.db.sentence.str.SQLBuilder;
import com.kinyx.framework.db.sentence.str.SQL;

public class DELETE__Tester {

	final DELETE delete = SQLBuilder.delete("T_DEMO");

	String defaultSentenceSQL = "DELETE FROM T_DEMO";

	protected void test(final DELETE delete, final String expectedSentence, final String expectedString) {
		Assert.assertEquals(expectedSentence, delete.getSentence());
		Assert.assertEquals(expectedString, delete.toString());
	}

	String defaultStringSQL = "SQL: [" + this.defaultSentenceSQL + "], params: []";

	@Test
	public void test0() {
		this.test(this.delete, this.defaultSentenceSQL, this.defaultStringSQL);
	}

	@Test
	public void demo1() {
		final String sentence = "DELETE FROM T_DEMO WHERE ID = ?";
		final String str = "SQL: [" + sentence + "], params: [foo]";
		this.test(//
				SQLBuilder.delete("T_DEMO")//
						.where(//
								new SQL().x("ID = ?", "foo")//
						)//
				, sentence, str);
	}

	@Test
	public void demo2() {
		final String sentence = "DELETE FROM T_DEMO WHERE (ID = ?)";
		final String str = "SQL: [" + sentence + "], params: [foo]";
		this.test(//
				SQLBuilder.delete("T_DEMO")//
						.where(//
								new SQL().x("(ID = ?)", "foo")//
						)//
				, sentence, str);
	}

}
